﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.Utils.Filtering;
using EyFramework.Common;
using EyFramework.Library;
using Ncov2019.Core.Service;
using Ncov2019.Entity;

namespace Ncov2019
{
    public partial class FrmNocvOrderFree : FrmDevBase
    {
        private INcovOrderRecordService ncovOrderRecordService;

        private List<GridColumnInfo> columnInfos = new List<GridColumnInfo>();

        public FrmNocvOrderFree()
        {
            InitializeComponent();
        }

        private void FrmNocvOrderFree_Load(object sender, EventArgs e)
        {
            ncovOrderRecordService = Globals.GetService<INcovOrderRecordService>();
            InitForm();
            QueryData();
        }

        private void InitForm()
        {
            gvData.ShowRowNum();
            gcData.ShowContextMenu(this.components);//显示右键导出功能
            #region
            columnInfos.Add(new GridColumnInfo("ORDER_SEQ", "开单序号", 100));
            columnInfos.Add(new GridColumnInfo("CHT_ID", "病历号码", 100, false));
            columnInfos.Add(new GridColumnInfo("PAT_NM", "姓名", 100));
            columnInfos.Add(new GridColumnInfo("BIRTHDAY", "出生日期", 100));
            columnInfos.Add(new GridColumnInfo("SEX_NM", "性别", 100));
            columnInfos.Add(new GridColumnInfo("ID_NO", "身份证号", 100));
            columnInfos.Add(new GridColumnInfo("TELPHONE", "联系电话", 100));
            columnInfos.Add(new GridColumnInfo("DEPARTMENT", "部门", 100));
            columnInfos.Add(new GridColumnInfo("ORD_DT", "开单日期", 100)
            {
                Formattype = FormatType.DateTime,
                Formatstring = "yyyy-MM-dd HH:mm:ss"
            });
            #endregion
            de_start.Text = ncovOrderRecordService.GetCurrentDate("yyyy-MM-dd");
            de_end.Text = de_start.Text;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            ShowLoading();
            try
            {
                QueryData();
            }
            finally
            {
                CloseLoading();
            }
        }

        private void QueryData()
        {
            NcovRecordParam param = new NcovRecordParam()
            {
                department= "老派出所采样点",
                START_DT = de_start.DateTime.ToString("yyyy-MM-dd"),
                END_DT = de_end.DateTime.ToString("yyyy-MM-dd"),
            };
            var ncovRecords = ncovOrderRecordService.QueryData(param);
            gcData.DataSource = ncovRecords;
            DevPublic.SetGridControlView(gvData, columnInfos, true, true);
        }

        private void btnSingleOrder_Click(object sender, EventArgs e)
        {
            FrmSingleOrder frmSingleOrder = new FrmSingleOrder();
            if (frmSingleOrder.ShowDialog() == DialogResult.OK)
            {
                QueryData();
            }
        }

        private void CancelOrder()
        {
            NcovOrderCacnel ncovOrderCacnel = new NcovOrderCacnel()
            {
                hos_code = "0001",
                reservation_no = "1000564167"
            };
            bool result = ncovOrderRecordService.CancelNcovFreeOrder(ncovOrderCacnel);
        }
    }
}